package com.sphd.emanu.activity.vipdetails;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.sphd.emanu.mvp.BasePresenterImpl;
import com.sphd.emanu.pojo.vip.MemberForOrg;
import com.sphd.emanu.utils.GsonUtil;
import com.wzutils.L;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class VipdetailsPresenter extends BasePresenterImpl<VipdetailsContract.View> implements VipdetailsContract.Presenter {

    @Override
    public void findMember(int org, Integer id) {
        emanuService.findMember(org, id).enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                L.e(response.toString());
                MemberForOrg memberForOrg = GsonUtil.GsonToBean(response.body(), MemberForOrg.class);
                mView.recBean(memberForOrg);
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                Error(t);
            }
        });
    }

    @Override
    public void addCouponForMember(int member, int number, int org) {
        emanuService.addCouponForMember(member, number, org).enqueue(new Callback<JsonObject>() {
            @Override
            public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                mView.recRes(res(response));
            }

            @Override
            public void onFailure(Call<JsonObject> call, Throwable t) {
                Error(t);
            }
        });
    }
}
